Motivation
https://research.stlouisfed.org/publications/economic-synopses/2013/08/13/mind-the-regional-output-gap/
# Read combined statistical areas: https://www.census.gov/geo/maps-data/data/cbf/cbf_msa.html
cbsa <- combined_statistical_areas(cb = FALSE, resolution = "5m", year = 2017)
trying URL 'http://www2.census.gov/geo/tiger/TIGER2017/CSA/tl_2017_us_csa.zip'
Content type 'application/zip' length 11353157 bytes (10.8 MB)
==================================================
downloaded 10.8 MB
# states
states <- states(cb = FALSE, resolution = "5m", year = 2017)
trying URL 'http://www2.census.gov/geo/tiger/TIGER2017/STATE/tl_2017_us_state.zip'
Content type 'application/zip' length 9284383 bytes (8.9 MB)
==================================================
downloaded 8.9 MB
# state gdp (Bureau of Economic Advisors: https://www.bea.gov/regional/downloadzip.cfm)
state_gdp <- read_csv('QGSP_ALL_R.csv') %>%
filter(IndustryId == 1)
Parsed with column specification:
cols(
.default = col_character(),
Region = col_integer(),
ComponentId = col_integer(),
IndustryId = col_integer(),
`2006Q1` = col_integer(),
`2006Q2` = col_integer(),
`2006Q3` = col_integer(),
`2006Q4` = col_integer(),
`2007Q4` = col_integer()
)
See spec(...) for full column specifications.
number of columns of result is not a multiple of vector length (arg 1)3 parsing failures.
row # A tibble: 3 x 5 col row col expected actual file expected <int> <chr> <chr> <chr> <chr> actual 1 1441 <NA> 57 columns 1 columns 'QGSP_ALL_R.csv' file 2 1442 <NA> 57 columns 2 columns 'QGSP_ALL_R.csv' row 3 1443 <NA> 57 columns 1 columns 'QGSP_ALL_R.csv'
# convert Quarterly data to numeric
state_gdp[, grepl( "Q" , names( state_gdp ) ) ] <- state_gdp[, grepl( "Q" , names( state_gdp ) ) ] %>%
lapply(function(x) as.numeric(as.character(x)))
# plot the shapes to ensure we have the metro areas
leaflet(states) %>%
addTiles() %>%
addPolygons() %>%
setMapWidgetStyle()